﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BawangMemo.BawangMemoView.View
{
    /// <summary>
    /// CourseInfoView.xaml 的交互逻辑
    /// </summary>
    public partial class CourseInfoView : UserControl
    {
        string _courseName;

        public CourseInfoView()
        {
            InitializeComponent();
        }

        public CourseInfoView(string courseName, double progress)
        {
            _courseName = courseName;
            InitializeComponent();

            label.Content = courseName + "  完成度  " + (progress * 100) + "%";
            progressBar.Value = progress * 100;
        }

        #region CourseEvent

        public static readonly RoutedEvent CourseEvent = EventManager.RegisterRoutedEvent("Course", RoutingStrategy.Bubble,
            typeof(RoutedEventHandler), typeof(TagListView));

        public event RoutedEventHandler CourseEventHandler
        {
            add
            {
                AddHandler(CourseEvent, value);
            }
            remove
            {
                RemoveHandler(CourseEvent, value);
            }
        }

        #endregion

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            CourseEventArgs args = new CourseEventArgs(true, _courseName, CourseEvent);
            RaiseEvent(args);
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            CourseEventArgs args = new CourseEventArgs(false, _courseName, CourseEvent);
            RaiseEvent(args);
        }
    }

    public class CourseEventArgs : RoutedEventArgs
    {
        bool _isLoad;
        string _course;

        public CourseEventArgs(bool isLoad, string course, RoutedEvent e)
            : base(e)
        {
            _isLoad = isLoad;
            _course = course;
        }

        public bool IsLoad
        {
            get
            {
                return _isLoad;
            }
        }

        public string CourseName
        {
            get
            {
                return _course;
            }
        }
    }

}
